package com.zwps.biz.domain.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwps.biz.api.enums.ZGoodsMaterialsEnum;
import com.zwps.biz.api.model.vo.structure.ZGoodsMaterialsTypeVO;
import com.zwps.biz.api.model.vo.structure.ZGoodsMaterialsVO;
import com.zwps.biz.dal.db.dao.ZGoodsMaterialsDAO;
import com.zwps.biz.dal.db.object.ZGoodsMaterialsDO;
import com.zwps.biz.domain.converter.ZGoodsMaterialsConverter;
import com.zwps.biz.domain.service.ZGoodsMaterialsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
@DS("qclyt")
@Service
public class ZGoodsMaterialsServiceImpl extends ServiceImpl<ZGoodsMaterialsDAO, ZGoodsMaterialsDO>
        implements ZGoodsMaterialsService {

    @Override
    public List<ZGoodsMaterialsTypeVO> geZGoodsMaterials() {
        List<ZGoodsMaterialsTypeVO> list = new ArrayList<>();
        List<ZGoodsMaterialsDO> materialsList = this.list();
        if (CollUtil.isEmpty(materialsList)){
            return list;
        }
        Map<Integer, List<ZGoodsMaterialsDO>> materialsMap =
                materialsList.stream().collect(Collectors.groupingBy(ZGoodsMaterialsDO::getType));

        for (ZGoodsMaterialsEnum value : ZGoodsMaterialsEnum.values()) {
            List<ZGoodsMaterialsDO> materialsDOS = materialsMap.get(value.getValue());
            if (CollUtil.isEmpty(materialsDOS)){
                continue;
            }
            ZGoodsMaterialsTypeVO vo = new ZGoodsMaterialsTypeVO();
            List<ZGoodsMaterialsVO> zGoodsMaterialsVOS = ZGoodsMaterialsConverter.INSTANCE.toZGoodsMaterialsVOList(materialsDOS);
            for (ZGoodsMaterialsVO zGoodsMaterialsVO : zGoodsMaterialsVOS) {
                zGoodsMaterialsVO.setStaffName("李启映");
                zGoodsMaterialsVO.setPhone("15923407152");
            }
            vo.setMaterials(zGoodsMaterialsVOS);
            vo.setTypeName(value.getDescription());
            list.add(vo);
        }
        return list;
    }
}




